#include <stdio.h>
#include <stdlib.h>
#include "stack_base_array.h"



STACK *stack_create(int cap)
{
    STACK *stack = malloc(sizeof(STACK));
    stack->arr = malloc(cap * sizeof(int));

    stack->cap = cap;
    stack->top = 0;

    return stack;
}



/*销毁*/
void stack_destroy(STACK *stack)
{
    free(stack->arr);
    free(stack);
}

/*压入*/
void stack_push(STACK *stack, int data)
{
    stack->arr[stack->top++] = data;
}

/*弹出*/
int stack_pop(STACK *stack)
{
    return stack->arr[--stack->top];
}


/*清空*/
void stack_clear(STACK *stack)
{
    stack->top = 0;
}

/*栈大小*/
int stack_size(STACK *stack)
{
    return stack->top;
}

/*判满*/
int stack_full(STACK *stack)
{
    if(stack->top >= stack->cap)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

/*判空*/
int stack_empty(STACK *stack)
{
    return !stack->top;
}





